module Oauth2::Weibo
  FLOWY_URL             = 'http://flowy.oopsdata.com'
  # oopsdata
  WEIBO_CLIENT_ID       = "2855748750"
  WEIBO_CLIENT_SECRET   = "3c07d73e3d5f6516c77cbff26ebfba61"
  # WEIBO_CALLBACK_URL  = "http://flowy.oopsdata.net/weibo"
  WEIBO_CALLBACK_URL    = "http://flowy.oopsdata.com/weibo"
  # WEIBO_CALLBACK_URL    = "http://flowy.dev/weibo"
  WEIBO_ACCESS_URL      = ""

  def params(options)
    {
      :access_token => self.access_token,
    }.merge!(options)
  end

  def create_comment(comment, mid, uid)
    result = Utility.post_j 'https://api.weibo.com/2/comments/create.json', params(
      :comment => comment,
      :id => mid,
      :comment_ori => 0
    )
    result["api_name"] = "create_comment"
    if error = error_rescue(result)
      return [error, result]
    else
      return [false, result]
    end
  end

  def add_comment(comment, mid, uid)
    result = Utility.post_j 'https://api.weibo.com/2/comments/create.json', params(
      :comment => comment,
      :id => mid,
      :comment_ori => 0
    )
    result
  end

  def mentions(since_id = '0')
    Utility.get_j 'https://api.weibo.com/2/statuses/mentions.json', params(
      :since_id => since_id
      )
  end

  def show_comments(wid, since_id = 0)
    Utility.get_j 'https://api.weibo.com/2/comments/show.json', params(:id => wid, :since_id => since_id)
  end

  def destroy_comment_batch(tweets)
    if (_tw = tweets.split(',')).length == 1
      destroy_comment(_tw[0])
    else
      Utility.post_j 'https://api.weibo.com/2/comments/destroy_batch.json', params(:cids => tweets)
    end
  end

  def destroy_comment(cid)
    Utility.post_j  'https://api.weibo.com/2/comments/destroy.json', params(:cid => cid)
  end

end
